<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>我的收藏</title>
		[#include "/common/include.ftl"/]
		<link type="text/css" rel="styleSheet" href="${base}/resource/css/member.css">
		<script type="text/javascript" src="${base}/resource/js/member.js"></script>
		<script type="text/javascript">
			$(function(){
				$("#topCheckedAll,#buttomCheckedAll").change(function(){
					var flag = this.checked;
					$(":checkbox").each(function(i,item){
						item.checked = flag;
					});
				});
			});
			function cancel(goodsId, goodsName){
				if(!goodsId){
					oDialog.prompt("请选择要取消关注的商品");
					return;
				}
				oDialog.confirm("确定取消对【" + goodsName + "】的关注?", function(){
					remove([goodsId]);
				});
			}
			
			function batchCancel(){
				var goodsIds = [];
				$(":checkbox:checked").each(function(index,item){
					if(!item.id){
						goodsIds.push(item.value);
					}
				});
				if(goodsIds.length == 0){
					oDialog.prompt("请选择要取消关注的商品");
					return;
				}
				oDialog.confirm("确定对选中的" + goodsIds.length + "种商品取消关注?", function(){
					remove(goodsIds);
				});
			}
			
			function remove(goodsIds){
				if(goodsIds.length == 0){
					oDialog.prompt("请选择要取消关注的商品");
					return;
				}
				ajax({
					url	: base + '/member/deleteFavorite.jhtml',
					data: {
						goodsIds	: goodsIds
					},
					success	: function(data){
						oDialog.prompt("取消关注成功");
						$.each(goodsIds,function(index,item){
							$(":checkbox[value='" + item + "']").parent().parent().remove();
						});
					}
				});
			}
			
			function batchAddCart(){
				var goodsIds = [];
				$(":checkbox:checked").each(function(index,item){
					if(!item.id){
						goodsIds.push(item.value);
					}
				});
				if(goodsIds.length == 0){
					oDialog.prompt("请选择要加入购物车的商品");
					return;
				}
				ajax({
					url	: base + '/cart/batchAdd.jhtml',
					data: {
						goodsIds	: goodsIds
					},
					success	: function(data){
						refreshCartHtml();
						oDialog.prompt("加入购物车成功");
					}
				});
			}
		</script>
	</head>
	[#macro Pagination pager]
		[#compress]
			<div id="title-pager" class="fr">
				<span>共有 ${pager.totalCount} 条记录</span>
				<span><i>${pager.pageNumber}</i>/${pager.pageCount}</span>
				<a class="next" [#if (pager.pageNumber < pager.pageCount)]href="/member/favorite.jhtml?pageNumber=${pager.pageNumber+1}"[/#if]>下一页</a>
				<a class="prev" [#if (pager.pageNumber > 1)]href="/member/favorite.jhtml?pageNumber=${pager.pageNumber-1}"[/#if]>上一页</a>
			</div>
		[/#compress]
	[/#macro]
	<body class="customer">
		[#include "/common/header.ftl"/]
		<div class="crumbs">
			<a href="${base}/member/index.jhtml">会员中心</a>
			<i style='font-family: simsun;font-style: normal;'>></i>
			<a>交易管理</a>
			<i style='font-family: simsun;font-style: normal;'>></i>
			<a>我的收藏</a>
		</div>
		<div id="member-main">
			[#assign menuNo='favorite'/]
			[#include "/common/member-left.ftl"/]
			<div class="member-right">
				<div class="right-wrap">
					<h2 class="right-title">我的收藏</h2>
					<div class="favorite-table">
						<table>
							<tr class="action">
								<th colspan="7">
									<div class="fl">
										<input type="checkbox" id="topCheckedAll" style="margin-left: 10px">
										<label for="topCheckedAll">全选</label><a href="javascript:batchAddCart();">加入购物车</a><a href="javascript:batchCancel();">取消关注</a>
									</div>
									[@Pagination pager=pager/]
								</th>
							</tr>
							<tr>
								<th width="20">&nbsp;</th>
				                <th width="200">&nbsp;</th>
				                <th width="350">商品</th>
				                <th width="160">商品规格</th>
				                <!--<th width="150">生产企业</th>-->
				                <th width="100">价格</th>
								<th>操作</th>
							</tr>
							[#if pager.list?has_content]
								[#list pager.list as goods]
									<tr class="tb">
										<td>
											<input type="checkbox" style="margin-left:10px" value="${goods.id}">
										</td>
										<td>
											<div class="f-img">
												<a href="${base}/goods/${goods.id}.jhtml" target="_blank">
													<img class="lazy" data-original="[@Pic pic=goods.image_default!'' postfix='100x100'/]" postfix="100x100" height="100" width="100"/>
												</a>
											</div>
										</td>
										<td class="i-p">
											<p class="f-name">
												<a href="${base}/goods/${goods.id}.jhtml" target="_blank">${goods.name}</a>
											</p>
										</td>
										<td class="center">${(goods.spec)!''}</td>
										[#--<td class="center">${(goods.manufacturer)!''}</td>--]
										
										<td class="center">
											<span class="price">${currency(goods.price,true)}</span>
										</td>
										<td class="center">
											<p>
												<a href="javascript:addCart(${goods.id},1);" class="add-cart"></a>
											</p>
											<p><a href="javascript:cancel(${goods.id}, '${goods.name}');">取消关注</a></p>
										</td>
									</tr>
								[/#list]
							[#else]
								<tr>
									<th colspan="7" class="list-empty"><span>您还没有收藏的商品</span></th>
								</tr>
							[/#if]
							<tr class="action">
								<th colspan="7">
									<div class="fl">
										<input type="checkbox" id="buttomCheckedAll" style="margin-left: 10px">
										<label for="buttomCheckedAll">全选</label><a href="javascript:batchAddCart();">加入购物车</a><a href="javascript:batchCancel();">取消关注</a>
									</div>
									[@Pagination pager=pager/]
								</th>
							</tr>
						</table>
					</div>
				</div>
			</div>
			<div class="clear"></div>
		</div>
		[#include "common/footer-slidebar-lazyload.ftl"]
	</body>
</html>